﻿RTE2_RegisterToolbarButton("objectLink",
							"_layouts/STYLES/ObjectLink/objectlinkicon.png",
							"",
							"Embed Movie (YouTube etc)",
							OlButtonOnClick,
							OlButtonOnResetState,
							new Array());

//The method called when the object is clicked
function OlButtonOnClick(strBaseElementID, arguments) {
    //get reference to document currently being edited
    var docEditor = RTE_GetEditorDocument(strBaseElementID);
    if (docEditor == null) { return; }
    // get reference to selected text
    var selectedRange = docEditor.selection.createRange();

    //prompt user for object code to embed
    var obj = prompt("Enter the object embed code:", "<object>....etc");
    //insert the object embed code
    var curr = selectedRange.htmlText
    if (curr.length == 0)
    { curr = "Link"; }
    selectedRange.pasteHTML("<a class=\"RTEObjectLink\" href=\"#\" title=\"" + obj.replace(/\"/g, "'")
	+ "\">" + curr + "</a>");

    //restore selection
    RTE_RestoreSelection(strBaseElementID);

    return true;
}

//The method called when the buttons state is reset
function OlButtonOnResetState(strBaseElementID, arguments) {
    //get reference to document currently being edited
    var docEditor = RTE_GetEditorDocument(strBaseElementID);
    if (docEditor == null) { return; }
    
    //We want it always to be available
    RTE_TB_SetEnabledFromCondition(strBaseElementID, true, "objectLink");

    return true;

}